package com.xiaoyu.lanling.feature.chat.model.message

import `in`.srain.cube.request.JsonData
import com.xiaoyu.im.datamodel.AppMessage
import com.xiaoyu.lanling.common.Constant.MessageAttrsKey.GIFT
import com.xiaoyu.lanling.feature.chat.viewholder.ChatViewHolderManager
import com.xiaoyu.lanling.media.image.ImageLoadParam

class ChatMessageSendGiftItem(message: AppMessage) : ChatMessageSendBaseItem(message) {

    val title: String
    val content: String
    val image: String
    val imageLoadParam: ImageLoadParam

    init {
        val attrs: JsonData = message.payload.attrsCopy
        val giftJsonData: JsonData = attrs.optJson(GIFT)
        title = giftJsonData.optString("messageTitle")
        content = giftJsonData.optString("messageContent")
        image = giftJsonData.optString("icon")
        imageLoadParam = ImageLoadParam.newBuilder().setSizeInDP(60).setUrl(image).build()
    }

    override val childrenViewType: Int
        get() = ChatViewHolderManager.TYPE_SEND_GIFT
}